﻿using System.Threading.Tasks;
using K9Nano.Application.Settings;
using K9Nano.Runtime;
using K9Nano.Web.Configuration.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace K9Nano.Web.Configuration
{
    [ApiController]
    [Route("config/[Action]")]
    public class ConfigurationController: ControllerBase
    {
        private readonly ISessionContext _sessionContext;
        private readonly ISettingsAppService _settingsAppService;

        public ConfigurationController(ISessionContext sessionContext, ISettingsAppService settingsAppService)
        {
            _sessionContext = sessionContext;
            _settingsAppService = settingsAppService;
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<AppConfigDto> GetAll()
        {
            var settings = await _settingsAppService.GetAppSettingsAsync(HttpContext.RequestAborted);
            return new AppConfigDto
            {
                App = settings,
                Roles = _sessionContext.Roles
            };
        }
    }
}